/*
 * @author java_deng
 * @date 2025/3/11 21:08
 * @description
 */
package org.kaka.controller;

import org.kaka.dto.InstitutionDto;
import org.kaka.service.impl.InstitutionService;
import org.kaka.utils.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/ins")
public class InstitutionController extends BaseController{
    @Autowired
    private InstitutionService institutionService;

    @RequestMapping("/list")
    public ResponseData list(InstitutionDto institutionDto){
        List<InstitutionDto> list = institutionService.list(institutionDto);
        return success(list,list.size());
    }

    @RequestMapping("/get/{id}")
    public ResponseData list(@PathVariable Long id ){
        InstitutionDto list = institutionService.detail(id);
        return success(list,0);
    }

    @RequestMapping("/saveOrUpdate")
    public ResponseData saveOrUpdate(InstitutionDto institutionDto){
        Long id = institutionDto.getId();
        if(id==null){
            institutionService.save(institutionDto);
            return success("新增成功");
        }else {
            institutionService.update(institutionDto);
            return success("修改成功");
        }
    }

    @RequestMapping("/delete/{id}")
    public ResponseData delete(@PathVariable Long id){
        if(id==null){
            return fail("id不能为空");
        }else {
            institutionService.delete(id);
            return success("删除成功");
        }
    }
}
